package test.vo
{
	import _Pan3D.base.Camera3D;
	import _Pan3D.base.Focus3D;
	import _Pan3D.particle.FireParticle;
	
	import _me.Scene_data;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DProgramType;
	import flash.display3D.Context3DTextureFormat;
	import flash.geom.Vector3D;
	
	public class Lizhilizhi extends FireParticle
	{
		[Embed(source="../_File/nijia2/lizhi/texture/fensanPic.jpg")]
		private var roundfile:Class;
		public function Lizhilizhi(context:Context3D)
		{
			super(context);
		}
		override public function init():void{
			verterAry = new Vector.<Number>;
			verterAry2 = new Vector.<Number>;
			indexAry = new Vector.<uint>;
			var n:Number=10;
			xConfig=20;
			yConfig=100;
			zConfig=20;
			for(var j:int;j<num;j++){
				verterAry.push(-n,n,0,0,0);
				verterAry.push(n,n,0,1,0);
				verterAry.push(n,-n,0,1,1);
				verterAry.push(-n,-n,0,0,1);
				
				var xup:Number = (Math.random()-0.5)*xConfig;
				var yup:Number = (Math.random())*yConfig;
				var zup:Number = (Math.random()-0.5)*zConfig;
				var sc:Number = scConfig + Math.random()*0.5;
				var tdel:Number = Math.random();
				
				for(var i:int = 0;i<4;i++){
					verterAry2.push(xup,yup,zup,sc,tdel);
				}
				var begin:int = j*4;
				indexAry.push(begin,begin+1,begin+2,begin,begin+2,begin+3);
			}
			
			
			
			upLoadToGpu();
		}
		override protected function upLoadToGpu():void{
			verterBuffer = _context.createVertexBuffer(4*num,5);
			verterBuffer.uploadFromVector(verterAry,0,verterAry.length/5);
			
			verterBuffer2 = _context.createVertexBuffer(4*num,5);
			verterBuffer2.uploadFromVector(verterAry2,0,verterAry2.length/5);
			
			indexBuffer = _context.createIndexBuffer(indexAry.length);
			indexBuffer.uploadFromVector(indexAry,0,indexAry.length);
			
			if(textureBuffer == null){
				var bitmapdata:BitmapData = Bitmap(new roundfile()).bitmapData;
				textureBuffer = this._context.createTexture(bitmapdata.width, bitmapdata.height, Context3DTextureFormat.BGRA, true);
				textureBuffer.uploadFromBitmapData(bitmapdata);
			}
	
		}
		
		override public function updateMatrix():void{
			modelMatrix.identity();
			modelMatrix.prepend(Scene_data.cam3D.cameraMatrix);
			modelMatrix.prepend(posMatrix);
			updataPos();
		}
		override public function updataPos():void{
			posMatrix.identity();
			posMatrix.prependTranslation(this._x, this._y, this._z);
			posMatrix.prependRotation(-Scene_data.cam3D.angle_y , Vector3D.Y_AXIS);
		} 
	
		override public function setVc():void{
			this.updateMatrix();
			
			var _Cam:Camera3D=Scene_data.cam3D;
			var _focus_3d:Focus3D=Scene_data.focus3D;
			
			modelMatrix.identity();
			modelMatrix.prepend(_Cam.cameraMatrix);
			modelMatrix.prepend(posMatrix);
			
			tempM.identity();
			tempM.prependRotation(_Cam.angle_x  , Vector3D.X_AXIS);
			tempM.prependRotation(_Cam.angle_y  , Vector3D.Y_AXIS);
			
			_context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 4, modelMatrix, true);
			_context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 8, tempM, true);
			
			_context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, Vector.<Number>([-0.001, 0, 0, 1]));
			_context.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 12, Vector.<Number>([t, -0.001, -0.001, 0]));
			_context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, colorVec);
			t += 0.01;
		}
	}
}